#pragma once

#include "Action.h"
#include "helper.h"
#include "tinyxml/tinyxml.h"

class CScript
{
public:
	CScript();
	~CScript();

	void Init(HMODULE hModule);
	int Parse(const char* pData);
	int Exec();

	enum {
		SCRIPT_VALUE_SIZE = 1024,
	};

private:
	bool MakeValue(const wchar_t strKey[SCRIPT_VALUE_SIZE], wchar_t strValue[SCRIPT_VALUE_SIZE]);
	int GetValue(const wchar_t strKey[SCRIPT_VALUE_SIZE], wchar_t strValue[SCRIPT_VALUE_SIZE]);
	CAction* CreateAction(MYUI::TiXmlElement* pNode);
	int Parse(MYUI::TiXmlDocument* pDocument);

	struct ci_less : std::binary_function<std::wstring, std::wstring, bool>
	{
		// case-independent (ci) compare_less binary function
		struct nocase_compare : public std::binary_function< wchar_t, wchar_t, bool>
		{
			bool operator()(const wchar_t& c1, const wchar_t& c2) const
			{
				return tolower(c1) < tolower(c2);
			}
		};
		bool operator()(const std::wstring& s1, const std::wstring& s2) const
		{
			return std::lexicographical_compare(s1.begin(), s1.end(), // source range
				s2.begin(), s2.end(), // dest range
				nocase_compare());    // comparison
		}
	};

public:
	
	static CAction::Platform SystemPlatfrom;
	static std::wstring SystemVersion;
	static DWORD MajorVersion;
	static DWORD MinorVersion;

private:
	HMODULE m_hModule;
	std::vector<CAction*> m_vecAction;
	std::map<std::wstring, std::wstring, ci_less> m_mapValue;
};